from selenium.webdriver.common.by import By

from base.Base import Base


class Page(Base):
    dl_loc = (By.LINK_TEXT, '登录')

    # 点击登录方法
    def dl(self):
        self.click(self.dl_loc)

    name_loc = (By.NAME, 'username')

    # 输入账号
    def name_input(self):
        self.send_keys(self.name_loc, '17800382574')

    pwd_loc = (By.NAME, 'password')

    # 输入密码
    def pwd_input(self):
        self.send_keys(self.pwd_loc, '123456')

    login_loc = (By.XPATH, '//*[@id="theForm"]/div[5]/a')

    # 点击登录
    def login(self):
        self.click(self.login_loc)

    shouye_loc = (By.XPATH, '/html/body/div[3]/div[2]/ul/li[1]/a')

    yq1 = (By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a')
    # 断言1：验证是否登录成功
    def dy1(self):
        return self.get_text(self.yq1)

    # 点击首页
    def shouye(self):
        self.click(self.shouye_loc)

    search_loc = (By.CSS_SELECTOR, '#searchForm > div.header-search > input')

    # 搜索框输入
    def search(self):
        self.send_keys(self.search_loc, '手机')

    sou = (By.XPATH, '//*[@id="searchForm"]/div[2]/input')

    # 点击搜索
    def sousuo(self):
        self.click(self.sou)

    yq2 = (By.XPATH, '/html/body/div[4]/a[2]')
    # 断言2：当前商品列表是否为搜索结果列
    def dy2(self):
        return self.get_text(self.yq2)
